package com.itqhy.controller;


import cn.dsna.util.images.ValidateCode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@Controller
public class ImageCodeController {
    @RequestMapping("/imageCode")
    public void imageCode(HttpServletResponse response, HttpServletRequest request) throws IOException {
        response.setContentType("text/html;charset=UTF-8");
        //告诉客户端不缓存
        response.setCharacterEncoding("UTF-8");
        request.setCharacterEncoding("UTF-8");
        response.setHeader("pragma", "no-cache");
        response.setHeader("cache-control", "no-cache");
        response.setIntHeader("expires", 0);
        ValidateCode vc = new ValidateCode(125, 40, 4, 100);
        String code = vc.getCode();//得到生成的字符
        HttpSession session= request.getSession();
        session.setAttribute("code",vc.getCode());
        vc.write(response.getOutputStream());//在网页中输出
    }

}
